package com.phys2d.trashball;

import java.awt.Image;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.imageio.ImageIO;

public class Resources {
	
	private static ResolutionType CurrentResolution = ResolutionType.HIGH_800x480;
	private static Map<String,Image> imageCache = new HashMap<String, Image>();
	
	public class Images {
		public static final String BACKGROUND_IMAGE = "/background.png";
		public static final String WOODEN_BOX = "/box.png";
		public static final String TRASHBALL = "/trashball.png";
		public static final String JABULANI = "/jabulani-small.png";
		public static final String TRASH_CAN = "/trashcan.png";
		public static final String OFFICE_CHAIR = "/chair-office-side-high.png";
	}
	
	public enum ResolutionType {
		SMALL_320x240,
		MEDIUM_480x320,
		HIGH_800x480,
		TABLET_1024x600,
		IPAD_1024x768
	}

	public static Image getImage(String imageName) throws IOException {
		if(imageCache.keySet().contains(imageName)) {
			return imageCache.get(imageName);
		} else {
			Image imageBuffer = ImageIO.read(TrashWorld.class.getResourceAsStream(imageName));
			if(imageBuffer != null) {
				imageCache.put(imageName, imageBuffer);
			} else {
				throw new IOException("Image not found: " + imageName);
			}
			return imageBuffer;
		}
	}
}
